package org.lt.resume.dao.resumedao;

import java.util.List;

import org.lt.resume.domain.resume.Resume;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class ResumeDAO extends HibernateDaoSupport {

	public void addResume(Resume resume) {
		this.getHibernateTemplate().save(resume);
	}

	public void updateResume(Resume resume) {
		this.getHibernateTemplate().update(resume);
	}

	public void deleteResume(Resume resume) {
		this.getHibernateTemplate().delete(resume);
	}

	public Resume findResumeByName(String username) {
		List resumes = this.getHibernateTemplate().find(
				"From Resume r where r.username = '" + username + "'");
		if (resumes.isEmpty()) {
			return null;
		}
		Resume resume = (Resume) resumes.get(0);
		return resume;
	}
	
	public Resume findResumeById(int id) {
		List resumes = this.getHibernateTemplate().find(
				"From Resume r where r.id = " + id);
		if (resumes.isEmpty()) {
			return null;
		}
		Resume resume = (Resume) resumes.get(0);
		return resume;
	}
	
	public List finResumesByUsername(String userName) {
		return this.getHibernateTemplate().find(
				"From Resumes r where r.username like '%" + userName + "%'");
	}

}
